﻿Imports System.ComponentModel

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class ucPeriodClassDetails
    Inherits UcBaseEditControl
    Implements IUcEditControl

#Region "Designer"
    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Friend WithEvents MaxGradelbl As System.Windows.Forms.Label
    Friend WithEvents MaxGrade As org.codegen.win.controls.CGIntTextBox
    Friend WithEvents PassGradelbl As System.Windows.Forms.Label
    Friend WithEvents PassGrade As org.codegen.win.controls.CGIntTextBox

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.PeriodIdlbl = New System.Windows.Forms.Label()
        Me.LessonIdlbl = New System.Windows.Forms.Label()
        Me.PeriodId = New org.codegen.win.controls.CGComboBox(Me.components)
        Me.LessonId = New org.codegen.win.controls.CGComboBox(Me.components)
        Me.MaxGradelbl = New System.Windows.Forms.Label()
        Me.MaxGrade = New org.codegen.win.controls.CGIntTextBox(Me.components)
        Me.PassGradelbl = New System.Windows.Forms.Label()
        Me.PassGrade = New org.codegen.win.controls.CGIntTextBox(Me.components)
        CType(Me.ErrProvider, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'PeriodIdlbl
        '
        Me.PeriodIdlbl.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.PeriodIdlbl.Location = New System.Drawing.Point(10, 26)
        Me.PeriodIdlbl.Name = "PeriodIdlbl"
        Me.PeriodIdlbl.Size = New System.Drawing.Size(92, 20)
        Me.PeriodIdlbl.TabIndex = 0
        Me.PeriodIdlbl.Text = "Period"
        Me.PeriodIdlbl.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'LessonIdlbl
        '
        Me.LessonIdlbl.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LessonIdlbl.Location = New System.Drawing.Point(10, 55)
        Me.LessonIdlbl.Name = "LessonIdlbl"
        Me.LessonIdlbl.Size = New System.Drawing.Size(92, 20)
        Me.LessonIdlbl.TabIndex = 1
        Me.LessonIdlbl.Text = "Lesson"
        Me.LessonIdlbl.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'PeriodId
        '
        Me.PeriodId.AssociatedLabel = Me.PeriodIdlbl
        Me.PeriodId.BackColor = System.Drawing.Color.LightYellow
        Me.PeriodId.ErrProvider = Nothing
        Me.PeriodId.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.PeriodId.isMandatory = True
        Me.PeriodId.Location = New System.Drawing.Point(108, 25)
        Me.PeriodId.MaxLength = 255
        Me.PeriodId.MaxValue = Nothing
        Me.PeriodId.MinValue = Nothing
        Me.PeriodId.Name = "PeriodId"

        Me.PeriodId.Size = New System.Drawing.Size(345, 21)
        Me.PeriodId.TabIndex = 0
        '
        'LessonId
        '
        Me.LessonId.AssociatedLabel = Me.LessonIdlbl
        Me.LessonId.BackColor = System.Drawing.Color.LightYellow
        Me.LessonId.ErrProvider = Nothing
        Me.LessonId.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LessonId.isMandatory = True
        Me.LessonId.Location = New System.Drawing.Point(108, 52)
        Me.LessonId.MaxLength = 255
        Me.LessonId.MaxValue = Nothing
        Me.LessonId.MinValue = Nothing
        Me.LessonId.Name = "LessonId"

        Me.LessonId.Size = New System.Drawing.Size(345, 21)
        Me.LessonId.TabIndex = 1
        '
        'MaxGradelbl
        '
        Me.MaxGradelbl.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.MaxGradelbl.Location = New System.Drawing.Point(10, 80)
        Me.MaxGradelbl.Name = "MaxGradelbl"
        Me.MaxGradelbl.Size = New System.Drawing.Size(92, 20)
        Me.MaxGradelbl.TabIndex = 5
        Me.MaxGradelbl.Text = "Max Grade"
        Me.MaxGradelbl.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'MaxGrade
        '
        Me.MaxGrade.AssociatedLabel = Me.MaxGradelbl
        Me.MaxGrade.BackColor = System.Drawing.Color.LightYellow
        Me.MaxGrade.ErrProvider = Nothing
        Me.MaxGrade.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.MaxGrade.FormatPattern = Nothing
        Me.MaxGrade.isMandatory = True
        Me.MaxGrade.Location = New System.Drawing.Point(108, 79)
        Me.MaxGrade.MaxLength = 255
        Me.MaxGrade.MaxValue = Nothing
        Me.MaxGrade.MinValue = Nothing
        Me.MaxGrade.Name = "MaxGrade"

        Me.MaxGrade.Size = New System.Drawing.Size(79, 21)
        Me.MaxGrade.TabIndex = 4
        '
        'PassGradelbl
        '
        Me.PassGradelbl.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.PassGradelbl.Location = New System.Drawing.Point(276, 82)
        Me.PassGradelbl.Name = "PassGradelbl"
        Me.PassGradelbl.Size = New System.Drawing.Size(92, 20)
        Me.PassGradelbl.TabIndex = 7
        Me.PassGradelbl.Text = "Pass Grade"
        Me.PassGradelbl.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'PassGrade
        '
        Me.PassGrade.AssociatedLabel = Me.PassGradelbl
        Me.PassGrade.BackColor = System.Drawing.Color.LightYellow
        Me.PassGrade.ErrProvider = Nothing
        Me.PassGrade.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.PassGrade.FormatPattern = Nothing
        Me.PassGrade.isMandatory = True
        Me.PassGrade.Location = New System.Drawing.Point(374, 81)
        Me.PassGrade.MaxLength = 255
        Me.PassGrade.MaxValue = Nothing
        Me.PassGrade.MinValue = Nothing
        Me.PassGrade.Name = "PassGrade"

        Me.PassGrade.Size = New System.Drawing.Size(79, 21)
        Me.PassGrade.TabIndex = 6
        '
        'ucPeriodClassDetails
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange
        Me.Controls.Add(Me.MaxGradelbl)
        Me.Controls.Add(Me.MaxGrade)
        Me.Controls.Add(Me.PassGradelbl)
        Me.Controls.Add(Me.PassGrade)
        Me.Controls.Add(Me.PeriodIdlbl)
        Me.Controls.Add(Me.PeriodId)
        Me.Controls.Add(Me.LessonIdlbl)
        Me.Controls.Add(Me.LessonId)
        Me.Name = "ucPeriodClassDetails"
        Me.Size = New System.Drawing.Size(803, 121)
        CType(Me.ErrProvider, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

    

    Friend WithEvents PeriodIdlbl As System.Windows.Forms.Label
    Friend WithEvents PeriodId As CGComboBox
    Friend WithEvents LessonIdlbl As System.Windows.Forms.Label
    Friend WithEvents LessonId As CGComboBox


#End Region

#Region "Properties"


#End Region

#Region "Methods"

    ''' <summary>
    ''' Fills the controls on the screen from data in the object
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub _loadData() Handles Me.evLoadObjectData

        
        Dim mo As PeriodClass = DirectCast(Me.ModelObject(), PeriodClass)
        Me.PeriodId.Value = mo.PeriodId
        Me.LessonId.Value = mo.LessonId
        Me.PassGrade.value = mo.PassGrade
        Me.MaxGrade.value = mo.MaxGrade

    End Sub

   
    ''' <summary>
    ''' Loads the object from the database and then sets the proeperties 
    ''' of the object from values on the controls
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub _loadToObject() Handles Me.evLoadToObject

        Dim mo As PeriodClass = DirectCast(Me.ModelObject, PeriodClass)
        mo.PeriodId = Me.PeriodId.intValue
        mo.LessonId = Me.LessonId.intValue
        mo.setPassGrade(CStr(Me.PassGrade.Text))
        mo.setMaxGrade(Me.MaxGrade.Text)

    End Sub

    Public Sub setLessonsDatasource(ByVal lessonsDs As List(Of Lesson))

        lessonsDs.Sort(Function(p1, p2) _
            p1.LessonDescription.CompareTo(p2.LessonDescription))

        Me.LessonId.DataSource = lessonsDs
        Me.LessonId.DisplayMember = "LessonDescription"
        Me.LessonId.ValueMember = "LessonId"

    End Sub

	Public Sub _InitializeControl() Handles Me.InitializeControl

		If Me.isInitialized = False Then
			'setup datasources here
			Dim lessonsDs As List(Of Lesson) = New BusObjects.Mappers.LessonDBMapper().findAll()

			Dim periodDs As List(Of Period) = New BusObjects.Mappers.PeriodDBMapper().findAll()
			periodDs.Sort(Function(p1, p2) _
				 -1 * p1.PeriodDate.GetValueOrDefault.CompareTo(p2.PeriodDate.GetValueOrDefault))


			Me.PeriodId.DataSource = periodDs
			Me.PeriodId.DisplayMember = "PeriodDescription"
			Me.PeriodId.ValueMember = "Periodid"
			

			Me.setLessonsDatasource(lessonsDs)

			Me.isInitialized = True
		End If

	End Sub

#End Region

    

    Private Sub LessonId_SelectedIndexChanged(ByVal sender As System.Object, _
                                              ByVal e As System.EventArgs) Handles LessonId.SelectedIndexChanged

        If Me.isInitialized Then
            If Me.LessonId.SelectedValue Is Nothing Then
                Me.MaxGrade.value = String.Empty
                Me.PassGrade.value = String.Empty
            Else
                Dim ls As Lesson = CType(Me.LessonId.SelectedItem, Lesson)
                Me.MaxGrade.value = ls.DefaultMaxGrade
                Me.PassGrade.value = ls.DefaultPassGrade
            End If

        End If
    End Sub
End Class


